package cn.tedu.charging.order.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.order.pojo.param.OrderAddParam;
import cn.tedu.charging.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "订单服务")
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping
    public JsonResult createOrder(@Validated @RequestBody OrderAddParam orderAddParam) throws Exception {
        log.debug("订单创建入参-{}", orderAddParam);
        String orderNo = orderService.createOder(orderAddParam);
        log.debug("订单调用service入参{},出参{}", orderAddParam, orderNo);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(2000);
        jsonResult.setMessage("订单创建成功");
        jsonResult.setData(orderNo);
        log.debug("订单创建成功-入参{},出参{}",orderAddParam,jsonResult);
        return jsonResult;
    }


}
